package ru.housewife.filters;

import ru.housewife.AppConstants;
import ru.housewife.cache.CacheManager;
import ru.housewife.form.UserForm;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @author troshanin
 *         Date: 04.02.14
 */
public class UserSessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        UserForm user = (UserForm) httpSessionEvent.getSession().getAttribute(AppConstants.SESSION_USER);
        if (user != null) {
            httpSessionEvent.getSession().removeAttribute(AppConstants.SESSION_USER);
            CacheManager.getInstance().onUserLogoff(user);
        }
    }
}
